#优化了输入方式、输入错误处理和程序退出方式
def calculate_bmr(gender, weight, height, age):
    if gender == "男":
        bmr = 13.7 * weight + 5.0 * height - 6.8 * age + 66
    elif gender == "女":
        bmr = 9.6 * weight + 1.8 * height - 4.7 * age + 655
    else:
        print("性别输入错误，请重新输入！")
        bmr = None
    return bmr


while True:
    try:
        gender, weight_str, height_str, age_str = input(
            "请输入性别（男/女）、体重（公斤）、身高（厘米）和年龄[空格隔开]: ").split()
        weight = float(weight_str)
        height = float(height_str)
        age = int(age_str)
    except ValueError:
        print("输入有误，请重新输入！")
        continue

    bmr = calculate_bmr(gender, weight, height, age)
    if bmr is not None:
        print("BMR 数值为：{:.2f}".format(bmr))

    y_or_n = input('是否退出程序(y/n)？')
    while y_or_n not in ['y', 'n']:
        print("输入有误，请重新输入！")
        y_or_n = input('是否退出程序(y/n)？')
    if y_or_n == 'y':
        break